<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="工作面" prop="face">
        <el-input
          v-model="queryParams.face"
          placeholder="请输入工作面"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班次" prop="shift">
        <el-select
          v-model="queryParams.shift"
          placeholder="请选择班次"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in shiftOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <!--<el-form-item label="当班计划产量" prop="shiftPlanYield">-->
      <!--<el-input-->
      <!--v-model="queryParams.shiftPlanYield"-->
      <!--placeholder="请输入当班计划产量"-->
      <!--clearable-->
      <!--size="small"-->
      <!--@keyup.enter.native="handleQuery"-->
      <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="当班实际产量" prop="shiftActualYield">-->
      <!--<el-input-->
      <!--v-model="queryParams.shiftActualYield"-->
      <!--placeholder="请输入当班实际产量"-->
      <!--clearable-->
      <!--size="small"-->
      <!--@keyup.enter.native="handleQuery"-->
      <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="当班计划进尺" prop="shiftPlanDrillingDepth">-->
      <!--<el-input-->
      <!--v-model="queryParams.shiftPlanDrillingDepth"-->
      <!--placeholder="请输入当班计划进尺"-->
      <!--clearable-->
      <!--size="small"-->
      <!--@keyup.enter.native="handleQuery"-->
      <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="当班实际进尺" prop="shiftActualDrillingDepth">-->
      <!--<el-input-->
      <!--v-model="queryParams.shiftActualDrillingDepth"-->
      <!--placeholder="请输入当班实际进尺"-->
      <!--clearable-->
      <!--size="small"-->
      <!--@keyup.enter.native="handleQuery"-->
      <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="当班超限进尺" prop="shiftExceedDrillingDepth">-->
      <!--<el-input-->
      <!--v-model="queryParams.shiftExceedDrillingDepth"-->
      <!--placeholder="请输入当班超限进尺"-->
      <!--clearable-->
      <!--size="small"-->
      <!--@keyup.enter.native="handleQuery"-->
      <!--/>-->
      <!--</el-form-item>-->
      <el-form-item label="带班领导" prop="shiftLeader">
        <el-input
          v-model="queryParams.shiftLeader"
          placeholder="请输入带班领导"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="瓦检员" prop="gasInspector">
        <el-input
          v-model="queryParams.gasInspector"
          placeholder="请输入瓦检员"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="安全员" prop="safetyInspector">
        <el-input
          v-model="queryParams.safetyInspector"
          placeholder="请输入安全员"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="值班调度员" prop="dutyDispatcher">
        <el-input
          v-model="queryParams.dutyDispatcher"
          placeholder="请输入值班调度员"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!--<el-form-item label="三违" prop="violations">-->
      <!--<el-input-->
      <!--v-model="queryParams.violations"-->
      <!--placeholder="请输入三违"-->
      <!--clearable-->
      <!--size="small"-->
      <!--@keyup.enter.native="handleQuery"-->
      <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="事故" prop="accident">-->
      <!--<el-input-->
      <!--v-model="queryParams.accident"-->
      <!--placeholder="请输入事故"-->
      <!--clearable-->
      <!--size="small"-->
      <!--@keyup.enter.native="handleQuery"-->
      <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="隐患查处" prop="hidden">-->
      <!--<el-input-->
      <!--v-model="queryParams.hidden"-->
      <!--placeholder="请输入隐患查处"-->
      <!--clearable-->
      <!--size="small"-->
      <!--@keyup.enter.native="handleQuery"-->
      <!--/>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="生产影响" prop="productionImpact">-->
      <!--<el-input-->
      <!--v-model="queryParams.productionImpact"-->
      <!--placeholder="请输入生产影响"-->
      <!--clearable-->
      <!--size="small"-->
      <!--@keyup.enter.native="handleQuery"-->
      <!--/>-->
      <!--</el-form-item>-->
      <!-- <el-form-item label="时间" prop="csDataTime">
        <el-date-picker
          clearable
          size="small"
          v-model="queryParams.csDataTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择时间"
        >
        </el-date-picker>
      </el-form-item> -->
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['riskWarning:sysSafetyProductionScheduling:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['riskWarning:sysSafetyProductionScheduling:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['riskWarning:sysSafetyProductionScheduling:remove']"
          >删除</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="sysSafetyProductionSchedulingList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" width="80" align="center">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.$index + 1 }}</span>  
        </template>
      </el-table-column>
      <!--<el-table-column label="主键" align="center" prop="id" />-->
      <el-table-column
        label="工作面"
        align="center"
        prop="face"
        show-overflow-tooltip
      />
      <el-table-column
        label="班次"
        align="center"
        prop="shift"
        :formatter="shiftFormat"
        show-overflow-tooltip
      />
      <el-table-column
        label="当班计划产量"
        align="center"
        prop="shiftPlanYield"
        width="100"
        show-overflow-tooltip
      />
      <el-table-column
        label="当班实际产量"
        align="center"
        prop="shiftActualYield"
        width="100"
        show-overflow-tooltip
      />
      <el-table-column
        label="当班计划进尺"
        align="center"
        prop="shiftPlanDrillingDepth"
        width="100"
        show-overflow-tooltip
      />
      <el-table-column
        label="当班实际进尺"
        align="center"
        prop="shiftActualDrillingDepth"
        width="100"
        show-overflow-tooltip
      />
      <el-table-column
        label="当班超限进尺"
        align="center"
        prop="shiftExceedDrillingDepth"
        width="100"
        show-overflow-tooltip
      />
      <el-table-column
        label="带班领导"
        align="center"
        prop="shiftLeader"
        show-overflow-tooltip
      />
      <el-table-column
        label="瓦检员"
        align="center"
        prop="gasInspector"
        show-overflow-tooltip
      />
      <el-table-column
        label="安全员"
        align="center"
        prop="safetyInspector"
        show-overflow-tooltip
      />
      <el-table-column
        label="值班调度员"
        align="center"
        prop="dutyDispatcher"
        width="100"
        show-overflow-tooltip
      />
      <el-table-column
        label="三违"
        align="center"
        prop="violations"
        width="100"
        show-overflow-tooltip
      />
      <el-table-column
        label="事故"
        align="center"
        prop="accident"
        width="100"
        show-overflow-tooltip
      />
      <el-table-column
        label="隐患查处"
        align="center"
        prop="hidden"
        width="100"
        show-overflow-tooltip
      />
      <el-table-column
        label="生产影响"
        align="center"
        prop="productionImpact"
        width="100"
        show-overflow-tooltip
      />
      <el-table-column
        label="时间"
        align="center"
        prop="csDataTime"
        width="180"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.csDataTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="120"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['riskWarning:sysSafetyProductionScheduling:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['riskWarning:sysSafetyProductionScheduling:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改安全生产调度对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1000px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="工作面" prop="face">
              <el-input v-model="form.face" placeholder="请输入工作面" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="班次" prop="shift">
              <el-select
                v-model="form.shift"
                placeholder="请选择班次"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in shiftOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="当班计划产量" prop="shiftPlanYield">
              <el-input
                v-model="form.shiftPlanYield"
                placeholder="请输入当班计划产量"
                style="width: 85%"
              />
              <span
                style="text-align: center; width: 15%; display: inline-block"
                >吨</span
              >
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="当班实际产量" prop="shiftActualYield">
              <el-input
                v-model="form.shiftActualYield"
                placeholder="请输入当班实际产量"
                style="width: 85%"
              />
              <span
                style="text-align: center; width: 15%; display: inline-block"
                >吨</span
              >
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="当班计划进尺" prop="shiftPlanDrillingDepth">
              <el-input
                v-model="form.shiftPlanDrillingDepth"
                placeholder="请输入当班计划进尺"
                style="width: 85%"
              />
              <span
                style="text-align: center; width: 15%; display: inline-block"
                >米</span
              >
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="当班实际进尺" prop="shiftActualDrillingDepth">
              <el-input
                v-model="form.shiftActualDrillingDepth"
                placeholder="请输入当班实际进尺"
                style="width: 85%"
              />
              <span
                style="text-align: center; width: 15%; display: inline-block"
                >米</span
              >
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="当班超限进尺" prop="shiftExceedDrillingDepth">
              <el-input
                v-model="form.shiftExceedDrillingDepth"
                placeholder="请输入当班超限进尺"
                style="width: 85%"
              />
              <span
                style="text-align: center; width: 15%; display: inline-block"
                >米</span
              >
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="带班领导" prop="shiftLeader">
              <el-input
                v-model="form.shiftLeader"
                placeholder="请输入带班领导,多个用','分隔"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="瓦检员" prop="gasInspector">
              <el-input
                v-model="form.gasInspector"
                placeholder="请输入瓦检员,多个用','分隔"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="安全员" prop="safetyInspector">
              <el-input
                v-model="form.safetyInspector"
                placeholder="请输入安全员,多个用','分隔"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="值班调度员" prop="dutyDispatcher">
              <el-input
                v-model="form.dutyDispatcher"
                placeholder="请输入值班调度员,多个用','分隔"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="三违" prop="violations">
              <el-input v-model="form.violations" placeholder="请输入三违" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="事故" prop="accident">
              <el-input v-model="form.accident" placeholder="请输入事故" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="隐患查处" prop="hidden">
              <el-input v-model="form.hidden" placeholder="请输入隐患查处" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="生产影响" prop="productionImpact">
              <el-input
                v-model="form.productionImpact"
                placeholder="请输入生产影响"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="时间" prop="csDataTime">
              <el-date-picker
                clearable
                size="small"
                v-model="form.csDataTime"
                type="date"
                value-format="yyyy-MM-dd"
                style="width: 100%"
                placeholder="选择时间"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listSysSafetyProductionScheduling,
  getSysSafetyProductionScheduling,
  delSysSafetyProductionScheduling,
  addSysSafetyProductionScheduling,
  updateSysSafetyProductionScheduling
} from '@/api/riskWarning/sysSafetyProductionScheduling'

export default {
  name: 'SysSafetyProductionScheduling',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 安全生产调度表格数据
      sysSafetyProductionSchedulingList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 班次字典
      shiftOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        face: null,

        shift: null,

        shiftPlanYield: null,

        shiftActualYield: null,

        shiftPlanDrillingDepth: null,

        shiftActualDrillingDepth: null,

        shiftExceedDrillingDepth: null,

        shiftLeader: null,

        gasInspector: null,

        safetyInspector: null,

        dutyDispatcher: null,

        violations: null,

        accident: null,

        hidden: null,

        productionImpact: null,

        csDataTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.getList()
    this.getDicts('shift').then(response => {
      this.shiftOptions = response.data
    })
  },
  methods: {
    /** 查询安全生产调度列表 */
    getList() {
      this.loading = true
      listSysSafetyProductionScheduling(this.queryParams).then(response => {
        this.sysSafetyProductionSchedulingList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 班次字典翻译
    shiftFormat(row, column) {
      return this.selectDictLabel(this.shiftOptions, row.shift)
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,

        face: null,

        shift: null,

        shiftPlanYield: null,

        shiftActualYield: null,

        shiftPlanDrillingDepth: null,

        shiftActualDrillingDepth: null,

        shiftExceedDrillingDepth: null,

        shiftLeader: null,

        gasInspector: null,

        safetyInspector: null,

        dutyDispatcher: null,

        violations: null,

        accident: null,

        hidden: null,

        productionImpact: null,

        csDataTime: null
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加安全生产调度'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getSysSafetyProductionScheduling(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = '修改安全生产调度'
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateSysSafetyProductionScheduling(this.form).then(response => {
              this.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addSysSafetyProductionScheduling(this.form).then(response => {
              this.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$confirm('是否确认删除当前选中数据？', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(function() {
          return delSysSafetyProductionScheduling(ids)
        })
        .then(() => {
          this.getList()
          this.msgSuccess('删除成功')
        })
        .catch(() => {})
    }
  }
}
</script>
